
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>线程的创建 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    
    <link rel="stylesheet" href="../../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-katex/katex.min.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-codeblock-label/block.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-click-reveal/click_reveal.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="part-3.html" />
    
    
    <link rel="prev" href="part-1.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../../">
            
                <a href="../../../">
            
                    
                    实验简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../../notes/log.html">
            
                <a href="../../../notes/log.html">
            
                    
                    更新日志
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">实验之前</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../../pre-lab/env.html">
            
                <a href="../../pre-lab/env.html">
            
                    
                    环境部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../../pre-lab/gdb.html">
            
                <a href="../../pre-lab/gdb.html">
            
                    
                    GDB 调试方法*
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">实验指导</li>
        
        
    
        <li class="chapter " data-level="3.1" >
            
                <span>
            
                    
                    实验指导零
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../../lab-0/guide/intro.html">
            
                <a href="../../lab-0/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../../lab-0/guide/part-1.html">
            
                <a href="../../lab-0/guide/part-1.html">
            
                    
                    创建项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../../lab-0/guide/part-2.html">
            
                <a href="../../lab-0/guide/part-2.html">
            
                    
                    移除标准库依赖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="../../lab-0/guide/part-3.html">
            
                <a href="../../lab-0/guide/part-3.html">
            
                    
                    移除运行时环境依赖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.5" data-path="../../lab-0/guide/part-4.html">
            
                <a href="../../lab-0/guide/part-4.html">
            
                    
                    编译为裸机目标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6" data-path="../../lab-0/guide/part-5.html">
            
                <a href="../../lab-0/guide/part-5.html">
            
                    
                    生成内核镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.7" data-path="../../lab-0/guide/part-6.html">
            
                <a href="../../lab-0/guide/part-6.html">
            
                    
                    调整内存布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.8" data-path="../../lab-0/guide/part-7.html">
            
                <a href="../../lab-0/guide/part-7.html">
            
                    
                    重写程序入口点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.9" data-path="../../lab-0/guide/part-8.html">
            
                <a href="../../lab-0/guide/part-8.html">
            
                    
                    使用 QEMU 运行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.10" data-path="../../lab-0/guide/part-9.html">
            
                <a href="../../lab-0/guide/part-9.html">
            
                    
                    接口封装和代码整理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.11" data-path="../../lab-0/guide/summary.html">
            
                <a href="../../lab-0/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.2" >
            
                <span>
            
                    
                    实验指导一
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.1" data-path="../../lab-1/guide/intro.html">
            
                <a href="../../lab-1/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.2" data-path="../../lab-1/guide/part-1.html">
            
                <a href="../../lab-1/guide/part-1.html">
            
                    
                    什么是中断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.3" data-path="../../lab-1/guide/part-2.html">
            
                <a href="../../lab-1/guide/part-2.html">
            
                    
                    RISC-V 中的中断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.4" data-path="../../lab-1/guide/part-3.html">
            
                <a href="../../lab-1/guide/part-3.html">
            
                    
                    程序运行状态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.5" data-path="../../lab-1/guide/part-4.html">
            
                <a href="../../lab-1/guide/part-4.html">
            
                    
                    状态的保存与恢复
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.6" data-path="../../lab-1/guide/part-5.html">
            
                <a href="../../lab-1/guide/part-5.html">
            
                    
                    进入中断处理流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.7" data-path="../../lab-1/guide/part-6.html">
            
                <a href="../../lab-1/guide/part-6.html">
            
                    
                    时钟中断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.8" data-path="../../lab-1/guide/summary.html">
            
                <a href="../../lab-1/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3" >
            
                <span>
            
                    
                    实验指导二
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="../../lab-2/guide/intro.html">
            
                <a href="../../lab-2/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="../../lab-2/guide/part-1.html">
            
                <a href="../../lab-2/guide/part-1.html">
            
                    
                    动态内存分配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="../../lab-2/guide/part-2.html">
            
                <a href="../../lab-2/guide/part-2.html">
            
                    
                    物理内存探测
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.4" data-path="../../lab-2/guide/part-3.html">
            
                <a href="../../lab-2/guide/part-3.html">
            
                    
                    物理内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.5" data-path="../../lab-2/guide/summary.html">
            
                <a href="../../lab-2/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" >
            
                <span>
            
                    
                    实验指导三
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.4.1" data-path="../../lab-3/guide/intro.html">
            
                <a href="../../lab-3/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.2" data-path="../../lab-3/guide/part-1.html">
            
                <a href="../../lab-3/guide/part-1.html">
            
                    
                    从虚拟地址到物理地址
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.3" data-path="../../lab-3/guide/part-2.html">
            
                <a href="../../lab-3/guide/part-2.html">
            
                    
                    修改内核
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.4" data-path="../../lab-3/guide/part-3.html">
            
                <a href="../../lab-3/guide/part-3.html">
            
                    
                    实现页表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.5" data-path="../../lab-3/guide/part-4.html">
            
                <a href="../../lab-3/guide/part-4.html">
            
                    
                    实现内核重映射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.6" data-path="../../lab-3/guide/part-5.html">
            
                <a href="../../lab-3/guide/part-5.html">
            
                    
                    页面置换*
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.7" data-path="../../lab-3/guide/summary.html">
            
                <a href="../../lab-3/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.5" >
            
                <span>
            
                    
                    实验指导四
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.5.1" data-path="intro.html">
            
                <a href="intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.2" data-path="part-1.html">
            
                <a href="part-1.html">
            
                    
                    线程和进程
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="3.5.3" data-path="part-2.html">
            
                <a href="part-2.html">
            
                    
                    线程的创建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.4" data-path="part-3.html">
            
                <a href="part-3.html">
            
                    
                    线程的切换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.5" data-path="part-4.html">
            
                <a href="part-4.html">
            
                    
                    线程的结束
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.6" data-path="part-5.html">
            
                <a href="part-5.html">
            
                    
                    内核栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.7" data-path="part-6.html">
            
                <a href="part-6.html">
            
                    
                    线程调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.8" data-path="summary.html">
            
                <a href="summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.6" >
            
                <span>
            
                    
                    实验指导五
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.6.1" data-path="../../lab-5/guide/intro.html">
            
                <a href="../../lab-5/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.2" data-path="../../lab-5/guide/part-1.html">
            
                <a href="../../lab-5/guide/part-1.html">
            
                    
                    设备树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.3" data-path="../../lab-5/guide/part-2.html">
            
                <a href="../../lab-5/guide/part-2.html">
            
                    
                    virtio
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.4" data-path="../../lab-5/guide/part-3.html">
            
                <a href="../../lab-5/guide/part-3.html">
            
                    
                    驱动和块设备驱动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.5" data-path="../../lab-5/guide/part-4.html">
            
                <a href="../../lab-5/guide/part-4.html">
            
                    
                    文件系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.6" data-path="../../lab-5/guide/summary.html">
            
                <a href="../../lab-5/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.7" >
            
                <span>
            
                    
                    实验指导六
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.7.1" data-path="../../lab-6/guide/intro.html">
            
                <a href="../../lab-6/guide/intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.2" data-path="../../lab-6/guide/part-1.html">
            
                <a href="../../lab-6/guide/part-1.html">
            
                    
                    构建用户程序框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.3" data-path="../../lab-6/guide/part-2.html">
            
                <a href="../../lab-6/guide/part-2.html">
            
                    
                    打包为磁盘镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.4" data-path="../../lab-6/guide/part-3.html">
            
                <a href="../../lab-6/guide/part-3.html">
            
                    
                    解析 ELF 文件并创建线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.5" data-path="../../lab-6/guide/part-4.html">
            
                <a href="../../lab-6/guide/part-4.html">
            
                    
                    实现系统调用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.6" data-path="../../lab-6/guide/part-5.html">
            
                <a href="../../lab-6/guide/part-5.html">
            
                    
                    处理文件描述符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.7" data-path="../../lab-6/guide/part-6.html">
            
                <a href="../../lab-6/guide/part-6.html">
            
                    
                    条件变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.8" data-path="../../lab-6/guide/summary.html">
            
                <a href="../../lab-6/guide/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">实验题</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../../lab-1/practice.html">
            
                <a href="../../lab-1/practice.html">
            
                    
                    实验一：中断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../../lab-2/practice.html">
            
                <a href="../../lab-2/practice.html">
            
                    
                    实验二：内存分配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../../lab-3/practice.html">
            
                <a href="../../lab-3/practice.html">
            
                    
                    实验三：虚实地址转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../practice-1.html">
            
                <a href="../practice-1.html">
            
                    
                    实验四（上）：线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../practice-2.html">
            
                <a href="../practice-2.html">
            
                    
                    实验四（下）：线程调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="../../lab-6/practice.html">
            
                <a href="../../lab-6/practice.html">
            
                    
                    实验六：系统调用
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">开发笔记</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../../format/partition.html">
            
                <a href="../../format/partition.html">
            
                    
                    文档代码划分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../../format/doc.html">
            
                <a href="../../format/doc.html">
            
                    
                    文档格式规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../../format/code.html">
            
                <a href="../../format/code.html">
            
                    
                    代码格式规范
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../.." >线程的创建</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x7EBF;&#x7A0B;&#x7684;&#x521B;&#x5EFA;">&#x7EBF;&#x7A0B;&#x7684;&#x521B;&#x5EFA;</h2>
<p>&#x63A5;&#x4E0B;&#x6765;&#xFF0C;&#x6211;&#x4EEC;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x76EE;&#x6807;&#x5C31;&#x662F;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x5E76;&#x4E14;&#x8BA9;&#x4ED6;&#x8FD0;&#x884C;&#x8D77;&#x6765;&#x3002;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x8981;&#x5F00;&#x59CB;&#x8FD0;&#x884C;&#xFF0C;&#x9700;&#x8981;&#x8FD9;&#x4E9B;&#x51C6;&#x5907;&#x5DE5;&#x4F5C;&#xFF1A;</p>
<ul>
<li>&#x5EFA;&#x7ACB;&#x9875;&#x8868;&#x6620;&#x5C04;&#xFF0C;&#x9700;&#x8981;&#x5305;&#x62EC;&#x4EE5;&#x4E0B;&#x6620;&#x5C04;&#x7A7A;&#x95F4;&#xFF1A;<ul>
<li>&#x7EBF;&#x7A0B;&#x6240;&#x6267;&#x884C;&#x7684;&#x4E00;&#x6BB5;&#x6307;&#x4EE4;</li>
<li>&#x7EBF;&#x7A0B;&#x6267;&#x884C;&#x6808;</li>
<li><em>&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x7684;&#x90E8;&#x5206;&#x5185;&#x5B58;&#x7A7A;&#x95F4;</em></li>
</ul>
</li>
<li>&#x8BBE;&#x7F6E;&#x8D77;&#x59CB;&#x6267;&#x884C;&#x7684;&#x5730;&#x5740;</li>
<li>&#x521D;&#x59CB;&#x5316;&#x5404;&#x79CD;&#x5BC4;&#x5B58;&#x5668;&#xFF0C;&#x6BD4;&#x5982; <code>sp</code></li>
<li>&#x53EF;&#x9009;&#xFF1A;&#x8BBE;&#x7F6E;&#x4E00;&#x4E9B;&#x6267;&#x884C;&#x53C2;&#x6570;&#xFF08;&#x4F8B;&#x5982; <code>argc</code> &#x548C; <code>argv</code>&#x7B49; &#xFF09;</li>
</ul>
<p>&#x601D;&#x8003;&#xFF1A;&#x4E3A;&#x4EC0;&#x4E48;&#x7EBF;&#x7A0B;&#x5373;&#x4FBF;&#x4E0E;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x65E0;&#x5173;&#xFF0C;&#x4E5F;&#x9700;&#x8981;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#x6620;&#x5C04;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x7684;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x5462;&#xFF1F;</p>
<div class="click_reveal"><span> Click to show </span><div><blockquote>
<p>&#x5F53;&#x53D1;&#x751F;&#x4E2D;&#x65AD;&#x65F6;&#xFF0C;&#x9700;&#x8981;&#x8DF3;&#x8F6C;&#x5230; <code>stvec</code> &#x6240;&#x6307;&#x5411;&#x7684;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x8FC7;&#x7A0B;&#x3002;&#x5982;&#x679C;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x7684;&#x5185;&#x5B58;&#x4E0D;&#x5728;&#x9875;&#x8868;&#x4E4B;&#x4E2D;&#xFF0C;&#x5C06;&#x65E0;&#x6CD5;&#x5904;&#x7406;&#x4E2D;&#x65AD;&#x3002;</p>
<p>&#x5F53;&#x7136;&#xFF0C;&#x4E5F;&#x4E0D;&#x662F;&#x6240;&#x6709;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x7684;&#x4EE3;&#x7801;&#x90FD;&#x9700;&#x8981;&#x88AB;&#x6620;&#x5C04;&#xFF0C;&#x4F46;&#x662F;&#x4E3A;&#x4E86;&#x5B9E;&#x73B0;&#x7B80;&#x4FBF;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x4E3A;&#x6BCF;&#x4E2A;&#x8FDB;&#x7A0B;&#x7684;&#x9875;&#x8868;&#x6620;&#x5C04;&#x5168;&#x90E8;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x7684;&#x5185;&#x5B58;&#x3002;&#x800C;&#x7531;&#x4E8E;&#x8FD9;&#x4E9B;&#x9875;&#x8868;&#x90FD;&#x6807;&#x8BB0;&#x4E3A;<strong>&#x5185;&#x6838;&#x6743;&#x9650;</strong>&#xFF08;&#x5373; <code>U</code> &#x4F4D;&#x4E3A; 0&#xFF09;&#xFF0C;&#x4E5F;&#x4E0D;&#x5FC5;&#x62C5;&#x5FC3;&#x7528;&#x6237;&#x7EBF;&#x7A0B;&#x53EF;&#x4EE5;&#x968F;&#x610F;&#x8BBF;&#x95EE;&#x3002;</p>
</blockquote>
</div></div>

<h3 id="&#x6267;&#x884C;&#x7B2C;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;">&#x6267;&#x884C;&#x7B2C;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;</h3>
<p>&#x56E0;&#x4E3A;&#x542F;&#x52A8;&#x7EBF;&#x7A0B;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x5404;&#x79CD;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x53C8;&#x8981;&#x4F7F;&#x7528;&#x6C47;&#x7F16;&#x4E86;&#x3002;&#x4E0D;&#x8FC7;&#xFF0C;&#x8FD9;&#x4E00;&#x6B21;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x5BF9; <code>interrupt.asm</code> &#x7A0D;&#x4F5C;&#x4FEE;&#x6539;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#x3002;</p>
<p>&#x5728; <code>interrupt.asm</code> &#x4E2D;&#x7684; <code>__restore</code> &#x6807;&#x7B7E;&#x73B0;&#x5728;&#x5C31;&#x80FD;&#x6D3E;&#x4E0A;&#x7528;&#x9014;&#x4E86;&#x3002;&#x539F;&#x672C;&#x8FD9;&#x6BB5;&#x6C47;&#x7F16;&#x4EE3;&#x7801;&#x7684;&#x4F5C;&#x7528;&#x662F;&#x5C06;&#x4E4B;&#x524D;&#x6240;&#x4FDD;&#x5B58;&#x7684; <code>Context</code> &#x6062;&#x590D;&#x5230;&#x5BC4;&#x5B58;&#x5668;&#x4E2D;&#xFF0C;&#x800C;&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x8BA9;&#x5B83;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x7CBE;&#x5FC3;&#x8BBE;&#x8BA1;&#x7684; <code>Context</code>&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x8BA9;&#x7A0B;&#x5E8F;&#x5728;&#x6062;&#x590D;&#x540E;&#x76F4;&#x63A5;&#x8FDB;&#x5165;&#x6211;&#x4EEC;&#x7684;&#x65B0;&#x7EBF;&#x7A0B;&#x3002;</p>
<p>&#x9996;&#x5148;&#x6211;&#x4EEC;&#x7A0D;&#x4F5C;&#x4FEE;&#x6539;&#xFF0C;&#x6DFB;&#x52A0;&#x4E00;&#x884C; <code>mv sp, a0</code>&#x3002;&#x539F;&#x672C;&#x8FD9;&#x91CC;&#x662F;&#x8BFB;&#x53D6;&#x4E4B;&#x524D;&#x5B58;&#x597D;&#x7684; <code>Context</code>&#xFF0C;&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x8BA9;&#x5176;&#x4ECE; <code>a0</code> &#x4E2D;&#x8BFB;&#x53D6;&#x6211;&#x4EEC;&#x8BBE;&#x8BA1;&#x597D;&#x7684; <code>Context</code>&#x3002;&#x8FD9;&#x6837;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x5728; Rust &#x4EE3;&#x7801;&#x4E2D;&#x8C03;&#x7528; <code>__restore(context)</code>&#x3002;</p>
<p></p><p class="code-label">os/src/interrupt/interrupt.asm</p><p></p>
<pre><code class="lang-asm">__restore:
    mv      sp, a0  # &#x52A0;&#x5165;&#x8FD9;&#x4E00;&#x884C;
    # ...
</code></pre>
<h4 id="&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5982;&#x4F55;&#x8BBE;&#x8BA1;-context-&#x5462;&#xFF1F;">&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5982;&#x4F55;&#x8BBE;&#x8BA1; <code>Context</code> &#x5462;&#xFF1F;</h4>
<ul>
<li>&#x901A;&#x7528;&#x5BC4;&#x5B58;&#x5668;<ul>
<li><code>sp</code>&#xFF1A;&#x5E94;&#x5F53;&#x6307;&#x5411;&#x8BE5;&#x7EBF;&#x7A0B;&#x7684;&#x6808;&#x9876;</li>
<li><code>a0</code>-<code>a7</code>&#xFF1A;&#x6309;&#x7167;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x89C4;&#x5219;&#xFF0C;&#x7528;&#x6765;&#x4F20;&#x9012;&#x53C2;&#x6570;</li>
<li><code>ra</code>&#xFF1A;&#x7EBF;&#x7A0B;&#x6267;&#x884C;&#x5B8C;&#x5E94;&#x8BE5;&#x8DF3;&#x8F6C;&#x5230;&#x54EA;&#x91CC;&#x5462;&#xFF1F;&#x5728;&#x540E;&#x7EED;<strong>&#x7CFB;&#x7EDF;&#x8C03;&#x7528;</strong>&#x7AE0;&#x8282;&#x6211;&#x4EEC;&#x4F1A;&#x4ECB;&#x7ECD;&#x6B63;&#x786E;&#x7684;&#x5904;&#x7406;&#x65B9;&#x5F0F;&#x3002;&#x73B0;&#x5728;&#xFF0C;&#x6211;&#x4EEC;&#x5148;&#x5C06;&#x5176;&#x8BBE;&#x4E3A;&#x4E00;&#x4E2A;&#x4E0D;&#x53EF;&#x6267;&#x884C;&#x7684;&#x5730;&#x5740;&#xFF0C;&#x8FD9;&#x6837;&#x7EBF;&#x7A0B;&#x4E00;&#x7ED3;&#x675F;&#x5C31;&#x4F1A;&#x89E6;&#x53D1;&#x9875;&#x9762;&#x5F02;&#x5E38;</li>
</ul>
</li>
<li><code>sepc</code><ul>
<li>&#x6267;&#x884C; <code>sret</code> &#x6307;&#x4EE4;&#x540E;&#x4F1A;&#x8DF3;&#x8F6C;&#x5230;&#x8FD9;&#x91CC;&#xFF0C;&#x6240;&#x4EE5; <code>sepc</code> &#x5E94;&#x5F53;&#x5B58;&#x50A8;&#x7EBF;&#x7A0B;&#x7684;&#x5165;&#x53E3;&#x5730;&#x5740;&#xFF08;&#x6267;&#x884C;&#x7684;&#x51FD;&#x6570;&#x5730;&#x5740;&#xFF09;</li>
</ul>
</li>
<li><code>sstatus</code><ul>
<li><code>spp</code> &#x4F4D;&#x6309;&#x7167;&#x7528;&#x6237;&#x6001;&#x6216;&#x5185;&#x6838;&#x6001;&#x6709;&#x6240;&#x4E0D;&#x540C;</li>
<li><code>spie</code> &#x4F4D;&#x4E3A; 1</li>
</ul>
</li>
</ul>
<blockquote>
<p><strong>[info] <code>sstatus</code> &#x6807;&#x5FD7;&#x4F4D;&#x7684;&#x5177;&#x4F53;&#x610F;&#x4E49;</strong></p>
<ul>
<li><code>spp</code>&#xFF1A;&#x4E2D;&#x65AD;&#x524D;&#x7CFB;&#x7EDF;&#x5904;&#x4E8E;&#x5185;&#x6838;&#x6001;&#xFF08;1&#xFF09;&#x8FD8;&#x662F;&#x7528;&#x6237;&#x6001;&#xFF08;0&#xFF09;</li>
<li><code>sie</code>&#xFF1A;&#x5185;&#x6838;&#x6001;&#x662F;&#x5426;&#x5141;&#x8BB8;&#x4E2D;&#x65AD;&#x3002;&#x5BF9;&#x7528;&#x6237;&#x6001;&#x800C;&#x8A00;&#xFF0C;&#x65E0;&#x8BBA; <code>sie</code> &#x53D6;&#x4F55;&#x503C;&#x90FD;&#x5F00;&#x542F;&#x4E2D;&#x65AD;</li>
<li><code>spie</code>&#xFF1A;&#x4E2D;&#x65AD;&#x524D;&#x662F;&#x5426;&#x5F00;&#x4E2D;&#x65AD;&#xFF08;&#x7528;&#x6237;&#x6001;&#x4E2D;&#x65AD;&#x65F6;&#x53EF;&#x80FD; <code>sie</code> &#x4E3A; 0&#xFF09;</li>
</ul>
<p><strong>&#x786C;&#x4EF6;&#x5904;&#x7406;&#x6D41;&#x7A0B;</strong></p>
<ul>
<li>&#x5728;&#x4E2D;&#x65AD;&#x53D1;&#x751F;&#x65F6;&#xFF0C;&#x7CFB;&#x7EDF;&#x8981;&#x5207;&#x6362;&#x5230;&#x5185;&#x6838;&#x6001;&#x3002;&#x6B64;&#x65F6;&#xFF0C;<strong>&#x5207;&#x6362;&#x524D;&#x7684;&#x72B6;&#x6001;</strong>&#x4F1A;&#x88AB;&#x4FDD;&#x5B58;&#x5728; <strong><code>spp</code></strong> &#x4F4D;&#x4E2D;&#xFF08;1 &#x8868;&#x793A;&#x5207;&#x6362;&#x524D;&#x5904;&#x4E8E;&#x5185;&#x6838;&#x6001;&#xFF09;&#x3002;&#x540C;&#x65F6;&#xFF0C;<strong>&#x5207;&#x6362;&#x524D;&#x662F;&#x5426;&#x5F00;&#x4E2D;&#x65AD;</strong>&#x4F1A;&#x88AB;&#x4FDD;&#x5B58;&#x5728; <strong><code>spie</code></strong> &#x4F4D;&#x4E2D;&#xFF0C;&#x800C; <code>sie</code> &#x4F4D;&#x4F1A;&#x88AB;&#x7F6E; 0&#xFF0C;&#x8868;&#x793A;&#x5173;&#x95ED;&#x4E2D;&#x65AD;&#x3002;</li>
<li>&#x5728;&#x4E2D;&#x65AD;&#x7ED3;&#x675F;&#xFF0C;&#x6267;&#x884C; <code>sret</code> &#x6307;&#x4EE4;&#x65F6;&#xFF0C;&#x4F1A;&#x6839;&#x636E; <code>spp</code> &#x4F4D;&#x7684;&#x503C;&#x51B3;&#x5B9A; <code>sret</code> &#x6267;&#x884C;&#x540E;&#x662F;&#x5904;&#x4E8E;&#x5185;&#x6838;&#x6001;&#x8FD8;&#x662F;&#x7528;&#x6237;&#x6001;&#x3002;&#x4E0E;&#x6B64;&#x540C;&#x65F6;&#xFF0C;<code>spie</code> &#x4F4D;&#x7684;&#x503C;&#x4F1A;&#x88AB;&#x5199;&#x5165; <code>sie</code> &#x4F4D;&#xFF0C;&#x800C; <code>spie</code> &#x4F4D;&#x7F6E; 1&#x3002;&#x8FD9;&#x6837;&#xFF0C;&#x7279;&#x6743;&#x72B6;&#x6001;&#x548C;&#x4E2D;&#x65AD;&#x72B6;&#x6001;&#x5C31;&#x5168;&#x90E8;&#x6062;&#x590D;&#x4E86;&#x3002;</li>
</ul>
<p><strong>&#x4E3A;&#x4F55;&#x5982;&#x6B64;&#x7E41;&#x7410;&#xFF1F;</strong></p>
<ul>
<li>&#x7279;&#x6743;&#x72B6;&#x6001;&#xFF1A;<br>&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x6D41;&#x7A0B;&#x5FC5;&#x987B;&#x5207;&#x6362;&#x5230;&#x5185;&#x6838;&#x6001;&#xFF0C;&#x6240;&#x4EE5;&#x4E2D;&#x65AD;&#x65F6;&#x9700;&#x8981;&#x7528; <code>spp</code> &#x6765;&#x4FDD;&#x5B58;&#x4E4B;&#x524D;&#x7684;&#x72B6;&#x6001;&#x3002;<br>&#x56DE;&#x5FC6;&#x8BA1;&#x7B97;&#x673A;&#x7EC4;&#x6210;&#x539F;&#x7406;&#x7684;&#x77E5;&#x8BC6;&#xFF0C;<code>sret</code> &#x6307;&#x4EE4;&#x5FC5;&#x987B;&#x540C;&#x65F6;&#x5B8C;&#x6210;&#x8DF3;&#x8F6C;&#x5E76;&#x5207;&#x6362;&#x72B6;&#x6001;&#x7684;&#x5DE5;&#x4F5C;&#x3002;</li>
<li>&#x4E2D;&#x65AD;&#x72B6;&#x6001;&#xFF1A;<br>&#x4E2D;&#x65AD;&#x521A;&#x53D1;&#x751F;&#x65F6;&#xFF0C;&#x5FC5;&#x987B;&#x5173;&#x95ED;&#x4E2D;&#x65AD;&#xFF0C;&#x4EE5;&#x4FDD;&#x8BC1;&#x73B0;&#x573A;&#x4FDD;&#x5B58;&#x7684;&#x8FC7;&#x7A0B;&#x4E0D;&#x4F1A;&#x88AB;&#x5E72;&#x6270;&#x3002;&#x540C;&#x7406;&#xFF0C;&#x73B0;&#x573A;&#x6062;&#x590D;&#x7684;&#x8FC7;&#x7A0B;&#x4E5F;&#x5FC5;&#x987B;&#x5173;&#x4E2D;&#x65AD;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x9700;&#x8981;&#x6709;&#x4EE5;&#x4E0A;&#x4E24;&#x4E2A;&#x786C;&#x4EF6;&#x81EA;&#x52A8;&#x6267;&#x884C;&#x7684;&#x64CD;&#x4F5C;&#x3002;<br>&#x7531;&#x4E8E;&#x4E2D;&#x65AD;&#x53EF;&#x80FD;&#x5D4C;&#x5957;&#xFF0C;&#x5728;&#x4FDD;&#x5B58;&#x73B0;&#x573A;&#x540E;&#xFF0C;&#x6839;&#x636E;&#x4E2D;&#x65AD;&#x7684;&#x79CD;&#x7C7B;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x518D;&#x5F00;&#x542F;&#x90E8;&#x5206;&#x4E2D;&#x65AD;&#x7684;&#x4F7F;&#x80FD;&#x3002;</li>
</ul>
</blockquote>
<p>&#x8BBE;&#x8BA1;&#x597D; <code>Context</code> &#x4E4B;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x5C06;&#x5B83;&#x5E94;&#x7528;&#x5230;&#x6240;&#x6709;&#x7684;&#x5BC4;&#x5B58;&#x5668;&#x4E0A;&#xFF08;&#x5373;&#x6267;&#x884C; <code>__restore</code>&#xFF09;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5207;&#x6362;&#x5230;&#x7B2C;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x4E86;&#x3002;</p>
<p></p><p class="code-label">os/src/main.rs: rust_main()</p><p></p>
<pre><code class="lang-rust"><span class="hljs-keyword">extern</span> <span class="hljs-string">&quot;C&quot;</span> {
    <span class="hljs-function"><span class="hljs-keyword">fn</span> <span class="hljs-title">__restore</span></span>(context: usize);
}
<span class="hljs-comment">// &#x83B7;&#x53D6;&#x7B2C;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x7684; Context&#xFF0C;&#x5177;&#x4F53;&#x539F;&#x7406;&#x540E;&#x9762;&#x8BB2;&#x89E3;</span>
<span class="hljs-keyword">let</span> context = PROCESSOR.lock().prepare_next_thread();
<span class="hljs-comment">// &#x542F;&#x52A8;&#x7B2C;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;</span>
<span class="hljs-keyword">unsafe</span> { __restore(context <span class="hljs-keyword">as</span> usize) };
<span class="hljs-built_in">unreachable!</span>()
</code></pre>
<h4 id="&#x4E3A;&#x4EC0;&#x4E48;-unreachable">&#x4E3A;&#x4EC0;&#x4E48; <code>unreachable</code></h4>
<p>&#x6211;&#x4EEC;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x7684; <code>__restore</code> &#x5E76;&#x6CA1;&#x6709; <code>ret</code> &#x6307;&#x4EE4;&#xFF0C;&#x751A;&#x81F3; <code>ra</code> &#x90FD;&#x4F1A;&#x88AB; <code>Context</code> &#x4E2D;&#x7684;&#x6570;&#x503C;&#x76F4;&#x63A5;&#x8986;&#x76D6;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#xFF0C;&#x4E00;&#x65E6;&#x6211;&#x4EEC;&#x6267;&#x884C;&#x4E86; <code>__restore(context)</code>&#xFF0C;&#x7A0B;&#x5E8F;&#x5C31;&#x65E0;&#x6CD5;&#x8FD4;&#x56DE;&#x5230;&#x8C03;&#x7528;&#x5B83;&#x7684;&#x4F4D;&#x7F6E;&#x4E86;&#x3002;<strong>&#x6CE8;&#xFF1A;&#x76F4;&#x63A5; jump &#x662F;&#x4E00;&#x4E2A;&#x975E;&#x5E38;&#x5371;&#x9669;&#x7684;&#x64CD;&#x4F5C;</strong>&#x3002;</p>
<p>&#x4F46;&#x662F;&#x6CA1;&#x6709;&#x5173;&#x7CFB;&#xFF0C;&#x6211;&#x4EEC;&#x4E5F;&#x4E0D;&#x9700;&#x8981;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x3002;&#x56E0;&#x4E3A;&#x5F00;&#x59CB;&#x6267;&#x884C;&#x7B2C;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#xFF0C;&#x610F;&#x5473;&#x7740;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x7684;&#x521D;&#x59CB;&#x5316;&#x5DF2;&#x7ECF;&#x5B8C;&#x6210;&#xFF0C;&#x518D;&#x56DE;&#x5230; <code>rust_main()</code> &#x4E5F;&#x6CA1;&#x6709;&#x610F;&#x4E49;&#x4E86;&#x3002;&#x751A;&#x81F3;&#x539F;&#x672C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x7684;&#x6808; <code>bootstack</code>&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x88AB;&#x56DE;&#x6536;&#xFF08;&#x4E0D;&#x8FC7;&#x6211;&#x4EEC;&#x73B0;&#x5728;&#x5C31;&#x4E22;&#x6389;&#x4E0D;&#x7BA1;&#x5427;&#xFF09;&#x3002;</p>
<h4 id="&#x5728;&#x542F;&#x52A8;&#x65F6;&#x4E0D;&#x6253;&#x5F00;&#x4E2D;&#x65AD;">&#x5728;&#x542F;&#x52A8;&#x65F6;&#x4E0D;&#x6253;&#x5F00;&#x4E2D;&#x65AD;</h4>
<p>&#x73B0;&#x5728;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x5728;&#x7EBF;&#x7A0B;&#x5F00;&#x59CB;&#x8FD0;&#x884C;&#x65F6;&#x5F00;&#x542F;&#x4E2D;&#x65AD;&#xFF0C;&#x800C;&#x5728;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x521D;&#x59CB;&#x5316;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x662F;&#x4E0D;&#x5E94;&#x8BE5;&#x6709;&#x4E2D;&#x65AD;&#x7684;&#x3002;&#x6240;&#x4EE5;&#xFF0C;&#x6211;&#x4EEC;&#x5220;&#x53BB;&#x4E4B;&#x524D;&#x8BBE;&#x7F6E;&#x300C;&#x5F00;&#x542F;&#x4E2D;&#x65AD;&#x300D;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<p></p><p class="code-label">os/interrupt/timer.rs</p><p></p>
<pre><code class="lang-rust"><span class="hljs-comment">/// &#x521D;&#x59CB;&#x5316;&#x65F6;&#x949F;&#x4E2D;&#x65AD;</span>
<span class="hljs-comment">///</span>
<span class="hljs-comment">/// &#x5F00;&#x542F;&#x65F6;&#x949F;&#x4E2D;&#x65AD;&#x4F7F;&#x80FD;&#xFF0C;&#x5E76;&#x4E14;&#x9884;&#x7EA6;&#x7B2C;&#x4E00;&#x6B21;&#x65F6;&#x949F;&#x4E2D;&#x65AD;</span>
<span class="hljs-keyword">pub</span> <span class="hljs-function"><span class="hljs-keyword">fn</span> <span class="hljs-title">init</span></span>() {
    <span class="hljs-keyword">unsafe</span> {
        <span class="hljs-comment">// &#x5F00;&#x542F; STIE&#xFF0C;&#x5141;&#x8BB8;&#x65F6;&#x949F;&#x4E2D;&#x65AD;</span>
        sie::set_stimer();
        <span class="hljs-comment">// &#xFF08;&#x5220;&#x9664;&#xFF09;&#x5F00;&#x542F; SIE&#xFF08;&#x4E0D;&#x662F; sie &#x5BC4;&#x5B58;&#x5668;&#xFF09;&#xFF0C;&#x5141;&#x8BB8;&#x5185;&#x6838;&#x6001;&#x88AB;&#x4E2D;&#x65AD;&#x6253;&#x65AD;</span>
        <span class="hljs-comment">// sstatus::set_sie();</span>
    }
    <span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x4E0B;&#x4E00;&#x6B21;&#x65F6;&#x949F;&#x4E2D;&#x65AD;</span>
    set_next_timeout();
}
</code></pre>
<h3 id="&#x5C0F;&#x7ED3;">&#x5C0F;&#x7ED3;</h3>
<p>&#x4E3A;&#x4E86;&#x6267;&#x884C;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x521D;&#x59CB;&#x5316;&#x6240;&#x6709;&#x5BC4;&#x5B58;&#x5668;&#x7684;&#x503C;&#x3002;&#x4E3A;&#x6B64;&#xFF0C;&#x6211;&#x4EEC;&#x9009;&#x62E9;&#x6784;&#x5EFA;&#x4E00;&#x4E2A; <code>Context</code> &#x7136;&#x540E;&#x8DF3;&#x8F6C;&#x81F3; <code>interrupt.asm</code> &#x4E2D;&#x7684; <code>__restore</code> &#x6765;&#x6267;&#x884C;&#xFF0C;&#x7528;&#x8FD9;&#x4E2A; <code>Context</code> &#x6765;&#x5199;&#x5165;&#x6240;&#x6709;&#x5BC4;&#x5B58;&#x5668;&#x3002;</p>
<h4 id="&#x601D;&#x8003;">&#x601D;&#x8003;</h4>
<p><code>__restore</code> &#x73B0;&#x5728;&#x4F1A;&#x5C06; <code>a0</code> &#x5BC4;&#x5B58;&#x5668;&#x89C6;&#x4E3A;&#x4E00;&#x4E2A; <code>*mut Context</code> &#x6765;&#x8BFB;&#x53D6;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x5728;&#x6267;&#x884C;&#x7B2C;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x65F6;&#x53EA;&#x9700;&#x8C03;&#x7528; <code>__restore(context)</code>&#x3002;</p>
<p>&#x90A3;&#x4E48;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x7A0B;&#x5E8F;&#x53D1;&#x751F;&#x4E86;&#x4E2D;&#x65AD;&#xFF0C;&#x6267;&#x884C;&#x5230; <code>__restore</code> &#x7684;&#x65F6;&#x5019;&#xFF0C;<code>a0</code> &#x7684;&#x503C;&#x53C8;&#x662F;&#x8C01;&#x8D4B;&#x4E88;&#x7684;&#x5462;&#xFF1F;</p>
<p><div id="page-footer" class="localized-footer"><hr><p><link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css"></p>
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
<div id="gitalk-container"></div>
<script>
    var gitalk = new Gitalk({
        clientID: "5084c46751a4b2f7cd4d",
        clientSecret: "3904f62d33aef24f19480fedc836a48b31d532e9",
        repo: "rCore-Tutorial-deploy",
        owner: "rcore-os",
        admin: [
            "chyyuu",
            "wangrunji0408",
            "xy-plus",
            "wyfcyx",
            "LyricZhao",
            "Tuyixiang"
        ],
        id: location.pathname.replace('/rCore-Tutorial-deploy', '').replace('.html', ''),
        distractionFreeMode: false
    });
    gitalk.render("gitalk-container");
</script></div></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="part-1.html" class="navigation navigation-prev " aria-label="Previous page: 线程和进程">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="part-3.html" class="navigation navigation-next " aria-label="Next page: 线程的切换">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"线程的创建","level":"3.5.3","depth":2,"next":{"title":"线程的切换","level":"3.5.4","depth":2,"path":"docs/lab-4/guide/part-3.md","ref":"docs/lab-4/guide/part-3.md","articles":[]},"previous":{"title":"线程和进程","level":"3.5.2","depth":2,"path":"docs/lab-4/guide/part-1.md","ref":"docs/lab-4/guide/part-1.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["hide-element","chapter-fold","katex","alerts","emphasize","mermaid-gb3","codeblock-label","code","search-pro","click-reveal","expandable-chapters-interactive","localized-footer"],"pluginsConfig":{"chapter-fold":{},"emphasize":{},"codeblock-label":{},"search-pro":{},"search":{},"localized-footer":{"filename":"gitalk.html","hline":"true"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"hide-element":{},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":1},"click-reveal":{},"highlight":{},"mermaid-gb3":{},"expandable-chapters-interactive":{},"alerts":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"docs/lab-4/guide/part-2.md","mtime":"2020-10-01T11:39:40.515Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-10-01T11:40:38.595Z"},"basePath":"../../..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../../../gitbook/gitbook.js"></script>
    <script src="../../../gitbook/theme.js"></script>
    
        
        <script src="../../../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-click-reveal/click_reveal.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    <script src="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

